package com.example.day0221.demon

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController


@Composable
fun  Demon06() {
    //导航控制器
    val navController = rememberNavController()

    //导航的首页,startDestination 代表首先显示哪个页面,builder 声明所有需要导航的地址
    NavHost(navController = navController, startDestination = "main", builder = {
        //声明第一个页面,当地址是main的时候,生成mainPage
        composable("main") { MainPage(navController = navController) }
        //composable("sec") { SecondPage() }
        composable("sec/{name}") {
            val student = it.arguments?.getString("name")
            SecondPage(student!!)
        }
    })
}

@Composable
fun MainPage(navController: NavController) {
    Text(
        text = "主页面",
        Modifier
            .fillMaxWidth()
            .background(Color.Yellow)
            .clickable {
                //通过地址进行跳转
               // navController.navigate("sec")
                val student = Student("LC", "LC", "0")
                navController.navigate("sec/$student")
            }
    )
}

@Composable
fun SecondPage(name:String) {
    Text(
        //text = "第二页面",
        text = "第二页面:$name",
        Modifier
            .fillMaxWidth()
            .background(Color.Green)
    )
}